home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / MSC2BC.ARJ / BASE_AFT.C next >
C/C++ Source or Header  |  1992-01-22  |  2KB  |  63 lines

  1. /* BASE_AFT.C - Microsoft C6.0a based heap example #2.
  2.    This program shows you one way to deal with the Microsoft
  3.    based heap constructs when converting to Borland C++ 3.0.
  4.    Typically, you would use based variables with compact, large,
  5.    or huge memory models, so this example substitutes equvalent
  6.    Borland C++ far heap memory management functions.
  7.  
  8.    Copyright (c) 1991 Borland International. All rights reserved.
  9.  
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <malloc.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. void main()
  18. {
  19.     /* Note 1 - based variables become _far variables */
  20.     char _far *revstr, *fwdstr;
  21.     /* Note 1 - ptrs to characters within the variables are also _far */
  22.     char _far *ptrrev, *ptrfwd;
  23.     /* Initialize a constant string */
  24.     char conststring[80] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  25.     int  lstr;
  26.  
  27.     /* Note 2 - No need to do based heap allocation call.
  28.        Allocate far memory for two strings of size (lstr+1) bytes.
  29.      */
  30.     lstr = strlen( conststring );
  31.     if( ((fwdstr = farmalloc( lstr + 1 )) == NULL) ||
  32.     ((revstr = farmalloc( lstr + 1 )) == NULL) )
  33.     /* Can't do, error exit 2 */
  34.     exit( 2 );
  35.  
  36.     /* Convert uppercase string to lowercase string after copying it to
  37.        far memory. The far functions no longer need recasting of
  38.        pointers.
  39.      */
  40.     _fstrlwr( _fstrcpy( fwdstr, conststring ) );
  41.  
  42.     /* Copy fwdstr string to revstr string in reversed order. */
  43.     /* You could also use either the _fstrrev function here, or
  44.        the ANS standard strrev function in a compact, large, or
  45.        huge memory model.
  46.     */
  47.     for( ptrfwd = fwdstr + lstr - 1, ptrrev = revstr;
  48.         ptrrev < revstr + lstr; ptrfwd--, ptrrev++ )
  49.     *ptrrev = *ptrfwd;
  50.     *ptrrev = '\0';
  51.  
  52.     /* Note 3 - Display the strings.
  53.        Recasting of based pointers is no longer required.
  54.     */
  55.     printf( "Forward string:  %Fs\n", fwdstr );
  56.     printf( "Reverse string:  %Fs\n", revstr );
  57.  
  58.     /* Note 4 - Free each memory block. */
  59.     farfree( fwdstr );
  60.     farfree( revstr );
  61.     exit( 0 );
  62. }
  63.